package demo;

import java.util.*;

public class didi01 {
    //子序列逆序列
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext()) {
            //记录组数
            int n = in.nextInt();
            while(n > 0) {
                //每次处理不同的数据组
                int total = in.nextInt();//每组数据的个数
                int[] nums = new int[total];
                for(int i = 0;i < total;i++) {
                    nums[i] = in.nextInt();//储存数组
                }
                prtNum(total,nums);
                n--;
            }
        }
    }

    static void prtNum(int total,int[] nums) {
        if(total == 1) {
            System.out.println(total);
            return;
        }
        //可以处理的数字有几位
        long sum = 0;
        for(int i = 0;i < total;i++) {
            if(i < total - 1 && nums[i] > nums[i + 1]) {
                break;
            }
            sum++;
        }
        if(sum == 1 || sum == 1) {
            System.out.println(1);
            return;
        }
        long ret = sum * sum - 1;
        System.out.println(ret % 998244353);
    }
}
